Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
15 / 15 |
| CategoryNormalizer | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
15 / 15 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| normalize | |
100.00% |
1 / 1 |
1 | |
100.00% |
11 / 11 |
|||
| supportsNormalization | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
| <?php | |
| /* | |
| * This file is part of the Akeneo PIM Enterprise Edition. | |
| * | |
| * (c) 2015 Akeneo SAS (http://www.akeneo.com) | |
| * | |
| * For the full copyright and license information, please view the LICENSE | |
| * file that was distributed with this source code. | |
| */ | |
| namespace Akeneo\Pim\Permission\Bundle\Normalizer\Flat; | |
| use Akeneo\Pim\Enrichment\Component\Category\Model\CategoryInterface; | |
| use Akeneo\Pim\Permission\Bundle\Manager\CategoryAccessManager; | |
| use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | |
| /** | |
| * Flat category normalizer | |
| * | |
| * @author Julien Sanchez <julien@akeneo.com> | |
| */ | |
| class CategoryNormalizer implements NormalizerInterface | |
| { | |
| /** @var array */ | |
| protected $supportedFormats = ['flat']; | |
| /** @var NormalizerInterface */ | |
| protected $categoryNormalizer; | |
| /** @var CategoryAccessManager */ | |
| protected $accessManager; | |
| /** | |
| * @param NormalizerInterface $categoryNormalizer | |
| * @param CategoryAccessManager $accessManager | |
| */ | |
| public function __construct(NormalizerInterface $categoryNormalizer, CategoryAccessManager $accessManager) | |
| { | |
| $this->categoryNormalizer = $categoryNormalizer; | |
| $this->accessManager = $accessManager; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| * | |
| * @param CategoryInterface $category | |
| */ | |
| public function normalize($category, $format = null, array $context = []) | |
| { | |
| $normalizedCategory = $this->categoryNormalizer->normalize($category, $format, $context); | |
| $normalizedCategory['view_permission'] = implode( | |
| array_map('strval', $this->accessManager->getViewUserGroups($category)), | |
| ',' | |
| ); | |
| $normalizedCategory['edit_permission'] = implode( | |
| array_map('strval', $this->accessManager->getEditUserGroups($category)), | |
| ',' | |
| ); | |
| $normalizedCategory['own_permission'] = implode( | |
| array_map('strval', $this->accessManager->getOwnUserGroups($category)), | |
| ',' | |
| ); | |
| return $normalizedCategory; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function supportsNormalization($data, $format = null) | |
| { | |
| return $data instanceof CategoryInterface && in_array($format, $this->supportedFormats); | |
| } | |
| } |